﻿@using Project.Resource.User 
@model Project.WebUI.Models.LogOnModel       
<div style="color: #444242; width: 400px;">       
    <div class="divInpUsername">
        <p>
            <span>Username</span>
            <input style="float:left; width:250px;" onkeypress="return EnterLogin(event)" class="cf_input" type="text" id="loginUser" />
        </p>        
    </div>
    <div class="divInpUsername">
        <p>
            <span>Password</span>
            <input style="width:250px;" onkeypress="return EnterLogin(event)" class="cf_input" type="password" id="loginPass" />
        </p>       
    </div>
   <div id="divError"></div>
    <div onclick="return login();" class="btLogin"></div>
</div>
<script type="text/javascript">
    function EnterLogin(e) {
        if (e.keyCode == 13) {
            login();
        }
    }
    function login() {
        name = $('#loginUser').val();
        pass = $('#loginPass').val();        
        if (name == "" && pass == '') {            
            $('#divError').html("@RegisterResource.UserName_Password");
            return false;
        } else if (pass == "" && name != "") {
            $('#divError').html("@RegisterResource.Password");
            return false;
        } else if (pass != "" && name == "") {
            $('#divError').html("@RegisterResource.UserName");
            return false;
        } else if (name != '' && pass != '') {
            $('#divError').html('<span style="color: #00b3f1; font-weight: bold;">Processing data...</span>');
            var url = '/User/Login';            
            $.post(url, {
                user: name,
                pass: pass
            },
                function (data) {
                    if (data == 1) {
                        location.href = "/";
                    }
                    if (data == "3") {
                        $('#divError').html('@RegisterResource.NotActive');
                    }
                    if (data == "2")
                    {
                        location.href = "/";
                    }
                    if(data=="0") {
                        $('#divError').html('@RegisterResource.LoginFailed');
                    }
                }
            );
        }
    }

    function reset() {
        $('#loginUser').val('');
        $('#loginPass').val('');
    }

    $(document).ready(function () {
        $('#loginUser').focus();
    });
</script>